package basic.socket.chat;
import java.io.DataInputStream;
import java.io.IOException;
import java.net.Socket;

/**
 * @author bingo
 * @Description
 * @Date 2018/7/20
 */
public class Receive implements Runnable {

    private  DataInputStream dis;
    private boolean isRunning;

    public Receive(Socket socket){
        isRunning = true;
        try {
           dis = new DataInputStream(socket.getInputStream());
        } catch (IOException e) {
            isRunning = false;
            e.printStackTrace();
        }
    }
    public void receive(){
        try {
         while (isRunning) {
             String info = dis.readUTF();
             System.out.println(info);
         }
     } catch (IOException e) {
         e.printStackTrace();
     }

 }
    @Override
    public void run() {

        receive();
    }

}
